package com.luo.demo;

/**
* @author: luosiyu
* @Description:
 * 属性有日（day）、月(month)、年(year)
 * 方法有明天（tomorrow）、昨天(yesteday)、一年中的第几天（daysinyear）
*/

public class Date {
    private int day;
    private int month;
    private int year;
    String date;
    String[] dateArray;
    public Date() {
        super();
    }
    //第一种构造方法
    public Date(Date d) {
        super();
        this.day = d.day;
        this.month = d.month;
        this.year = d.year;
    }

    //第二种构造方法
    public Date(int[] data) {
        this.day = data[0];
        this.month = data[1];
        this.year = data[2];

    }

    //第三种构造方法
    public Date(int day, int month, int year) {
        super();
        this.day = day;
        this.month = month;
        this.year = year;
    }

    //第四种构造方法
    public Date(String date) {
        this.dateArray = date.trim().split("-");
        this.year = Integer.parseInt(dateArray[0]);
        this.month = Integer.parseInt(dateArray[1]);
        this.day = Integer.parseInt(dateArray[2]);
    }

    public int getDay() {
        return day;
    }
    public void setDay(int day) {
        this.day = day;
    }
    public int getMonth() {
        return month;
    }
    public void setMonth(int month) {
        this.month = month;
    }
    public int getYear() {
        return year;
    }
    public void setYear(int year) {
        this.year = year;
    }

    public void tomorrow() {
        //明天
        if(day<year()){
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + year+"年"+month+"月"+(day+1)+"日");
        }else if(month<12){
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + year+"年"+(month+1)+"月1日");
        }else {
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + (year+1)+"年1月1日");
        }

    }
    public void yesteday() {
        //昨天
        if(day>1){
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + year+"年"+month+"月"+(day-1)+"日");
        }else if(month>1){
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + year+"年"+(month-1)+"月"+year()+"日");
        }else {
            System.out.println(year + "年" + month + "月" + day + "日" + "的明天是" + (year-1)+"年12月"+year()+"日");
        }
    }
    public void daysinyear() {
        //一年中的第几天
        int s=day;
        for(int i = 1;i<month;i++){
           s+= year();
        }
        System.out.println(year + "年" + month + "月" + day + "日" + "是一年中的第" + s + "天");
    }

    public int year(){
        int d;
        switch (month) {
            case 1:
            case 3:
            case 5:
            case 7:
            case 8:
            case 10:
            case 12:
                d = 31;
                break;
            case 4:
            case 6:
            case 9:
            case 11:
                d = 30;
                break;
            case 2:
//                d =yearday();
                if (year % 400 == 0 || year % 4 == 0 && year % 100 != 0)
                    d= 29;
                 else
                    d= 28;
                break;
            default:
                throw new IllegalStateException("Unexpected value: " + month);
        }
        return d;
    }
}
